package org.langqiao.io.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class FilePathTest {
	public static void main(String[] argStrings){
		File files = new File("D:/杂货铺");
		File[] filePaths  =  files.listFiles();
		if(filePaths == null){
			System.out.println("你输入的路径不存在");
		}else if(filePaths.length == 0){
			System.out.println("你输入路径下的文件夹没有文件");
		}else{
			String[] dataFile = new String[filePaths.length]; 
			for(int i=0;i<dataFile.length;i++){
				dataFile[i] = filePaths[i].getPath();
			}
			Arrays.sort(dataFile);
			readFile(dataFile[0]);
		}
	}

	public static void readFile(String filePath){
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath))));
			String line = null;
			int count = 0;
			while((line = br.readLine()) != null){
				count++;
				System.out.println(line.trim());
			}
			System.out.println("行数为："+count);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
